#!/usr/bin/python3.7
# -*- coding: utf-8 -*-
# @Time    : 2021/3/5 4:38 下午
# @Author  : 白辉东
# @Email   : xyxk-huidong.bai@ximalaya.com
# @File    : audioPlayer.py
# @Software: PyCharm

import os
import pygame
import time
from config import projectPath


class PlayController:
    def __init__(self, wake_word, pause):
        self._pause = pause
        # 小美小美，小雅小雅
        self.wake_word = wake_word

    def play_wake_music(self):
        audio = os.path.join(projectPath.WEAK_UP_AUDIO_DIR, f'{self.wake_word}.mp3')
        self._load(audio=audio)
        time.sleep(3)
        pygame.mixer.music.stop()

    def play_single_music(self, module, audio):
        audio = os.path.join(projectPath.AUDIO_DIR, module, f'{audio}.mp3')
        self._load(audio=audio)
        time.sleep(self._pause)
        pygame.mixer.music.stop()

    @staticmethod
    def _load(audio):
        pygame.mixer.init()
        pygame.mixer.pre_init(16000, -16, 2, 2048)
        pygame.mixer.init()
        pygame.mixer.music.load(audio)
        pygame.mixer.music.play()

    # todo 多轮查询
    def play_multi_music(self):
        pass


if __name__ == '__main__':
    player = PlayController('小雅小雅', 7)
    player.play_wake_music()

